﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace SchemaDeploy
{
    public class CDir
    {
        //Data
        private CVersionFileList _root;


        public string Name;
        public CVersionFileList Files;
        public CDirList Dirs;

        //Constr
        public CDir(CVersionFileList all) : this(all, "") { }
        public CDir(CVersionFileList all, string name)
        {
            _root = all;
            Load(all, name);
        }

        internal CDir(CVersionFileList all, string parent, string name) : this(all, parent.Length > 0 ? string.Concat(parent, "/", name) : name) { }
        private void Load(CVersionFileList all, string name)
        {
            this.Name = name;

            this.Files = all.InDir(name);
            this.Dirs = new CDirList(all, name);
        }

        public List<string> DirNamesRecursive
        {
            get
            {
                var list = new List<string>();
                if (Name.Length > 0)
                    list.Add(Name);
                foreach (var i in Dirs)
                    list.AddRange(i.DirNamesRecursive);
                return list;
            }
        }
        public Dictionary<string, CBinaryFile> FilesRecursive
        {
            get
            {
                var d = new Dictionary<string, CBinaryFile>();
                foreach (var i in Files)
                    d.Add(i.VFPath, i.BinaryFile);
                foreach (var i in Dirs)
                    foreach (var j in i.FilesRecursive)
                        d.Add(j.Key, j.Value);
                return d;
            }
        }
    }
}
